package com.vecspace.dayu.code.template.dao;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.vecspace.database.dao.BaseDao;
import com.vecspace.dayu.code.template.pojo.CodeFragment;

@Repository("dayu_codeFragmentDao")
public class CodeFragmentDao extends BaseDao{
	public CodeFragment getCodeFragment(Long id) throws Exception {
		CodeFragment codeFragment = this.queryObject(CodeFragment.class, id);
		this.evict(codeFragment);
		return codeFragment;
	}
	
	public void saveCodeFragment(CodeFragment codeFragment) throws Exception {
		this.saveOrUpdateObject(codeFragment);
		this.evict(codeFragment);
	}
	
	public void updateCodeTemplate(Long id, String codeTemplate) throws Exception {
		String sql = "update DAYU_CODE_FRAGMENT set CODE_TEMPLATE=? where id=?";
		this.updateDataRowBySql(sql, new Object[] {codeTemplate, id});
	}
	
	public void deleteCodeFragment(Long id) throws Exception {
		this.deleteObject(CodeFragment.class, id);
	}
	
	public List<CodeFragment> getAllCodeFragments() throws Exception{
		List<CodeFragment> codeFragments = this.queryObjectList("from CodeFragment order by name");
		return codeFragments;
	}
}
